<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('托管域名管理列表')" />
    <th:block th:include="include :: layout-latest-css" />
    <th:block th:include="include :: ztree-css" />
</head>
<body class="gray-bg">
    <div class="ui-layout-west">
        <div class="box box-main">
            <div class="box-header">
                <div class="box-title">
                    <i class="fa fa-sitemap"></i> 托管服务器
                </div>
                <div class="box-tools pull-right">
                    <a type="button" class="btn btn-box-tool" href="javascript:void(0)" onclick="serviceToPage()" title="托管服务器管理"><i class="fa fa-edit"></i></a>
                    <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新服务器"><i class="fa fa-refresh"></i></button>
                </div>
            </div>
            <div class="ui-layout-content">
                <div id="tree" class="ztree"></div>
            </div>
        </div>
    </div>
    <div class="ui-layout-center">
         <div class="container-div">
            <div class="row">
                <div class="col-sm-12 search-collapse">
                    <form id="formId">
                        <input type="hidden" name="stsId" id="stsId"/>
                        <input type="hidden" name="domainMainId" id="domainMainId"/>
                        <div class="select-list">
                            <ul>
                                <li>
                                    <label>托管域名：</label>
                                    <input type="text" name="sslDomain"/>
                                </li>
                                <li>
                                    <label>是否续签：</label>
                                    <select name="isAutoSsl" th:with="type=${@dict.getType('sys_yes_no')}">
                                        <option value="">所有</option>
                                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                    </select>
                                </li>
                                <li>
                                    <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                                </li>
                            </ul>
                        </div>
                    </form>
                </div>

                <div class="btn-group-sm" id="toolbar" role="group">
                    <!--<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="SSL:domain:add">
                        <i class="fa fa-plus"></i> 添加
                    </a>
                    <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="SSL:domain:edit">
                        <i class="fa fa-edit"></i> 修改
                    </a>
                    <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="SSL:domain:remove">
                        <i class="fa fa-remove"></i> 删除
                    </a>
                    <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="SSL:domain:export">
                        <i class="fa fa-download"></i> 导出
                    </a>-->
                </div>
                <div class="col-sm-12 select-table table-bordered">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: layout-latest-js" />
    <th:block th:include="include :: ztree-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('SSL:domain:edit')}]];
        var removeFlag = [[${@permission.hasPermi('SSL:domain:remove')}]];
        var domainDictList = [[${@dict.getType('domain_status')}]];
        var prefix = ctx + "SSL/domain";
        $(function() {
            var panehHidden = false;
            if ($(this).width() < 769) {
                panehHidden = true;
            }
            $('body').layout({ initClosed: panehHidden, west__size: 270, resizeWithWindow: false });
            // 回到顶部绑定
            if ($.fn.toTop !== undefined) {
                var opt = {
                    win:$('.ui-layout-center'),
                    doc:$('.ui-layout-center')
                };
                $('#scroll-up').toTop(opt);
            }
            queryDataList();
            queryServiceTree();
        });

        function serviceToPage() {
            var url = ctx + "SSL/service";
            $.modal.openTab("托管服务器管理", url);
        }

        $('#btnRefresh').click(function() {
            queryServiceTree();
        });

        function queryServiceTree(){
            var url = ctx + "SSL/service/queryTree";
            var options = {
                url: url,
                expandLevel: 2,
                onClick : zOnClick
            };
            $.tree.init(options);
            function zOnClick(event, treeId, treeNode) {
                if(treeNode.pId){
                    $("#stsId").val(treeNode.pId);
                    $("#domainMainId").val(treeNode.id);
                }else{
                    $("#domainMainId").val('');
                    $("#stsId").val(treeNode.id);
                }
                $.table.search();
            }
        }

        function queryDataList() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "托管域名管理",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '托管Id',
                    visible: false
                },
                {
                    field: 'createTime',
                    title: '创建时间'
                },
                {
                    field: 'stsName',
                    title: '所属托管服务器'
                },
                {
                    field: 'sslDir',
                    title: '证书文件夹'
                },
                {
                    field: 'sslDomain',
                    title: '托管域名'
                },
                {
                    field: 'daysDifference',
                    title: '过期时间',
                    formatter:function (value, row, index){
                        if(value){
                            if(value > 30){
                                return '<p><span class="badge badge-success">剩余：'+value+' 天</span></p>';
                            }else if (value <=30 && value > 20){
                                return '<p><span class="badge badge-primary">剩余：'+value+' 天</span></p>';
                            }else if (value <=20 && value > 10){
                                return '<p><span class="badge badge-warning">剩余：'+value+' 天</span></p>';
                            }else{
                                return '<p><span class="badge badge-danger">剩余：'+value+' 天</span></p>';
                            }
                        }else{
                            return '<p><span class="badge badge-danger">剩余：0 天</span></p>';
                        }
                    }
                },
                {
                    field: 'status',
                    title: '同步状态',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(domainDictList, value);
                    }
                },
                {
                    field: 'remark',
                    title: '备注',
                    formatter: function (value, row, index) {
                       if(value){
                           return value;
                       }
                       return "无";
                    }
                }]
            };
            $.table.init(options);
        }

        function isAutoSslTools(row) {
            if (row.isAutoSsl === 'N' || !row.isAutoSsl) {
                return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
            } else if(row.isAutoSsl === 'Y'){
                return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
            }
        }

        function disable(id) {
            $.modal.confirm("确认要关闭自动续签吗？", function() {
                $.operate.post(prefix + "/edit", { "id": id, "isAutoSsl": 'N' });
            })
        }

        function enable(id) {
            $.modal.confirm("确认要开启自动续签吗？", function() {
                $.operate.post(prefix + "/edit", { "id": id, "isAutoSsl": 'Y' });
            })
        }
    </script>
</body>
</html>
